//
//  PSGameSettings.h
//  PrefCore
//
//  Created by Sergey on 1/25/14.
//  Copyright (c) 2014 Play-on-smart. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "PSBid.h"

#define PS_ROSTOV_PASSING_TRICK_COST ((uint32_t)5)

/// Represents the flavor of the game rules.
typedef enum {
    kGameFlavorSochi
,   kGameFlavorLeningrad
,   kGameFlavorRostov
} PSGameFlavor;

/// Represents game levels.
typedef enum {
    kGameLevel0
,   kGameLevel1
,   kGameLevel2
,   kGameLevel3
} PSGameLevel;

/// Represents whist types.
typedef enum {
    kWhistGentleman
,   kWhistGreedy
} PSGameWhistType;

/// Represents a passing type.
typedef enum {
    kPassingTypeSliding
,   kPassingTypeClassic
} PSGamePassingType;

/// Represents a passing progression.
typedef enum {
    kPassingProgression_1111
,   kPassingProgression_123123
,   kPassingProgression_1233
,   kPassingProgression_1244
,   kPassingProgression_1234
,   kPassingProgression_1248
} PSGamePassingProgression;

/// Represents a passing trick cost.
typedef enum {
    kPassingTrickCost_1
,   kPassingTrickCost_2
} PSGamePassingTrickCost;

/// Represents a passing exit type.
typedef enum {
    kPassingExit_6666
,   kPassingExit_6777
,   kPassingExit_6788
,   kPassingExit_678678
} PSGamePassingExit;

/// Represents a misere catching mode.
typedef enum {
    kMisereCacthModeDefault
,   kMisereCacthModeHuman
,   kMisereCacthModeAI
} PSGameMisereCacthMode;

/// Represents a suit ordering in a hand.
typedef enum {
    kSuitOrderNone
,   kSuitOrderByColor
,   kSuitOrderByRank
} PSGameSuitOrder;

/// Represents a rank ordering in a hand.
typedef enum {
    kRankOrderAscending
,   kRankOrderDescending
} PSGameRankOrder;

/// Represent a confirmation mode.
typedef enum {
    kConfirmationNever
,   kConfirmationAlways
,   kConfirmationIntelligent
} PSGameConfirmation;

/// Represents a tricking 10 mode.
typedef enum {
    kTricking10Whisted
,   kTricking10Checked
} PSGameTricking10;

/// Represents game settings.
@interface PSGameSettings : NSObject

/// Retrieves the settings from user defaults. When a user default setting
/// does not exist, uses the default value.
/// @param userDefaults User defaults from which to read the settings.
+(instancetype)settingsFromUserDefaults:(NSUserDefaults*)userDefaults;

/// Writes these settings to the supplied user default instance.
/// @param userDefaults User defaults to which to write the settings.
-(void)saveToUserDefaults:(NSUserDefaults*)userDefaults;

/// Removes all keys specific to PSGameSettings from user defaults.
/// This method is intended for testing.
+(void)clearUserDefaults:(NSUserDefaults*)ud;

/// Determines if a passing sequence is allowed to reset after a misere.
/// @param tricks The number of tricks taken in a misere game.
-(BOOL)isPassingInterruptedByMisereWithTricks:(PSTrickCount)tricks;

/// Determines if a passing sequence is allowed to reset after a non-whisted game.
-(BOOL)isPassingInterruptedByNonWhistedGame;

/// Determines if a passing sequence is allowed to reset after a failed game.
-(BOOL)isPassingInterruptedByFailedGame;

/// The size of the pool for the game.
@property (nonatomic, readwrite) int poolSize;

/// The flavor of the game rules.
@property (nonatomic, readwrite) PSGameFlavor gameFlavor;

/// The passing type for the game.
@property (nonatomic, readwrite) PSGamePassingType passingType;

/// The passing progression of the game.
@property (nonatomic, readwrite) PSGamePassingProgression passingProgression;

/// Costs of a trick in a passing game.
@property (nonatomic, readwrite) PSGamePassingTrickCost passingTrickCost;

/// The rules of exiting the sequence of passing games.
@property (nonatomic, readwrite) PSGamePassingExit passingExit;

/// Determines who catches misere in this game.
@property (nonatomic, readwrite) PSGameMisereCacthMode misereCatchMode;

/// Determines how the game with ten tricks is to be played.
@property (nonatomic, readwrite) PSGameTricking10 trickingTen;

/// The type of whist for the game.
@property (nonatomic, readwrite) PSGameWhistType whistType;

/// Determines if the game of six spades needs a mandatory whist.
@property (nonatomic, readwrite) BOOL mandatoryWhistOnSixSpades;

/// Determines the display ordering of the suits in a hand.
@property (nonatomic, readwrite) PSGameSuitOrder suitOrder;

/// Determines the display ordering of the same-suit cards in a hand.
@property (nonatomic, readwrite) PSGameRankOrder rankOrder;

/// Determines if a gap needs to be displayed between suits in a hand.
@property (nonatomic, readwrite) BOOL spaceBetweenSuits;

/// Determines how bids should be confirmed.
@property (nonatomic, readwrite) PSGameConfirmation bidConfirmation;

/// Determines how contracts should be confirmed.
@property (nonatomic, readwrite) PSGameConfirmation contractConfirmation;

/// Determines if a tap is requied on ending a round when not playing.
@property (nonatomic, readwrite) BOOL roundEndTapWhenNotPlaying;

/// Determines if a tap is requied on ending a round when AI's move was
/// the last one in the round.
@property (nonatomic, readwrite) BOOL roundEndTapWhenLastMoverAi;

/// Determines if a tap is requied on ending a round when human's move was
/// the last one in the round.
@property (nonatomic, readwrite) BOOL roundEndTapWhenLastMoverHuman;

/// Determines if moves with a single choice should be automated.
@property (nonatomic, readwrite) BOOL automateObviousMoves;

/// Determines if a game should be skipped on pass.
@property (nonatomic, readwrite) BOOL skipGameOnPass;

/// Determines the level of a player with the specific id.
-(PSGameLevel)levelForPlayerId:(int)playerId;

// Sets the new level of a player with the specific id.
-(void)setLevel:(PSGameLevel)level forPlayerId:(int)playerId;

@end
